program List3;

{$APPTYPE CONSOLE}

uses
  SysUtils;

type
  pelement = ^element;
  element = record
    value: integer;
    next: pelement;
  end;

var
  head, head1: pelement;
  fin: textFile;
  n, i, num: integer;

procedure Add (var head: pelement; num: integer);
  var tmp: pelement;
  begin
    tmp:= head;
    new (head);
    head^.next:= tmp;
    head^.value:= num;
  end;

procedure AddToEnd (var head: pelement; num: integer);
  var current: pelement;
  begin
    if (head <> nil) then
    begin
      current:= head;
      while (current^.next <> nil) do
        current:= current^.next;
      new(current^.next);
      current^.next^.value:= num;
      current^.next^.next:= nil;
    end else begin
      Add (head, num);
    end;
  end;

function Delete (var head: pelement): integer;
  var tmp: pelement;
  begin
    tmp:= head^.next;
    Delete:= head^.value;
    dispose (head);
    head:= tmp;
  end;

procedure PrintList (head: pelement);
  var current: pelement;
  begin
    current:= head;
    while (current<>nil) do
    begin
      writeln (current^.value);
      current:= current^.next;
    end;
  end;

procedure BubbleSort1 (var head: pelement);
  var current, current1: pelement; k: integer;
  begin
  if (head^.next<>nil) then
  begin
    current:= head^.next;
    current1:=head;
    while (current<>nil) do
    begin
      if (current1^.value > current^.value) then
      begin
        n:=current1^.value;
        current1^.value:= current^.value;
        current^.value:=n;
      end;
      current1:= current1^.next;
      current:= current^.next;
      end;
    end;
  end;


procedure OverturningList (var head, head1: pelement);
  var current: pelement;
  begin
    current:=head;
    while (current <> nil) do
    begin
      Add (head1, current^.value);
      current:=current^.next;
    end;
  end;

begin
  new (head);
  head:= nil;
  //new (head1);
  //head1:= nil;
  assignFile (fin, 'input.txt');
  reset (fin);
  readln (fin, n);
  for i:= 1 to n do
    begin
      readln (fin, num);
      AddToEnd (head, num);
    end;
  printlist (head);
  BubbleSort1 (head);
  //OverturningList (head, head1);
  printlist (head);
  closeFile (fin);
  readln;
end.
